<?php

namespace Buu\Modules\Deployment\Service;

use Gitlab\Client;
use Gitlab\ResultPager;

/**
 *
 * Created by PhpStorm
 * Date: 2022/9/28
 * Time: 17:08
 * docs:
 */
class GitLab
{

    public Client $gitLab;


    public function __construct()
    {
        $client = new Client();
        $client->setUrl('https://git.haohaozhu.me');
        $client->authenticate('s_sReFds5icTJ7azC9ZY', Client::AUTH_HTTP_TOKEN);

        $this->gitLab = $client;
    }

    /**
     * 获取分支列表
     *
     * @param string $pathWithNamespace
     * @param array $parameters
     * @return mixed
     * @time 2022/9/28 17:12
     * @desc
     */
    public function getBranches(string $pathWithNamespace, array $parameters = [])
    {
        return $this->gitLab->repositories()->branches(urldecode($pathWithNamespace), $parameters);
    }


    /**
     * 获取分支详情
     *
     * @param string $pathWithNamespace
     * @param string $branch
     * @return mixed
     * @time 2022/9/28 17:12
     * @desc
     */
    public function getBranchInfo(string $pathWithNamespace, string $branch)
    {
        return $this->gitLab->repositories()->branch(urldecode($pathWithNamespace), $branch);
    }

}